package org.hs.phd.odi.tracking.tracker;

import java.awt.Polygon;
import java.beans.XMLDecoder;
import java.beans.XMLEncoder;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.HashMap;
import java.util.Map;

public class TrackInfo {

	private Map<Long, Polygon> perFrameShapes;
	
	public TrackInfo(){
		setPerFrameShapes(new HashMap<Long, Polygon>());
	}

	public Polygon getInfo(long frameNo) {
		return getPerFrameShapes().get(frameNo);
	}

	public boolean isInfoAvailable(long frameNo) {
		return getPerFrameShapes().containsKey(frameNo);
	}

	public void setInfo(long frameNo, Polygon shape) {
		getPerFrameShapes().put(frameNo, shape);
	}

	public Map<Long, Polygon> getPerFrameShapes() {
		return perFrameShapes;
	}

	public void setPerFrameShapes(Map<Long, Polygon> perFrameShapes) {
		this.perFrameShapes = perFrameShapes;
	}

	public static TrackInfo read(InputStream in) {
		XMLDecoder decoder = new XMLDecoder(in);
		TrackInfo trackinfo = (TrackInfo) decoder.readObject();
		decoder.close();
		return trackinfo;
	}

	public void load(InputStream in) {
		perFrameShapes = read(in).perFrameShapes;
	}

	public void save(OutputStream out) {
		XMLEncoder encoder = new XMLEncoder(out);
		encoder.writeObject(this);
		encoder.close();
	}

	
}
